/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.migrate.cbc;

import com.wtkj.vo.dzzf.base.kfwd.Account;
import com.wtkj.vo.dzzf.base.kfwd.FundAccount;
import com.wttech.dzzf.process.dao.DataInitilizingDao;
import com.wttech.dzzf.process.dao.ImportHisDataDao;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 删除错误插入的数据
 * @author MaShibo
 * @date 2017/12/26.
 */
@Service
public class DeleteErrorInsertDataService {

	private static final Logger LOGGER = LoggerFactory.getLogger(DeleteErrorInsertDataService.class);

	@Resource
	private ImportHisDataDao importHisDataDao;

	@Resource
	private DataInitilizingDao dataInitilizingDao;

	@Transactional(rollbackFor = Exception.class)
	public void process(FundAccount fundAccount){
		String fundAccountId = fundAccount.getFundAccountId();
		if (!StringUtils.equalsIgnoreCase(fundAccountId, "C1AR3D5D-CCBS-HIWY-CB05-000002008788")){
			importHisDataDao.deleteFundAccount(fundAccountId);
		}
		List<Account> accounts = dataInitilizingDao.queryAccountsByFundAccountId(fundAccountId);
		accounts.forEach(account -> {
			String accountId = account.getAccountId();
			if (!StringUtils.equalsIgnoreCase(accountId, "S2UB6A4T-U1S2-BD05-M05N-000002008788")){
				importHisDataDao.deleteAccount(accountId);
				importHisDataDao.deleteAccountOpt(accountId);
			}
		});
	}
}
